package com.corner.model.leancloud.base;

import android.content.Context;

import com.avos.avoscloud.AVOSCloud;
import com.avos.avoscloud.im.v2.AVIMClient;
import com.avos.avoscloud.im.v2.AVIMMessageManager;
import com.avos.avoscloud.im.v2.AVIMTypedMessage;
import com.corner.model.leancloud.helper.ChatEventHanlder;

public class BaseLeanCloud {
    public static boolean hasInit;

    public synchronized static void init(Context application) {
        if (hasInit) {
            return;
        }
        /** leanCloud的appID */
        String APP_ID = "owahavgdgylwnwm0nm5h7wlcgnqvy3kuo6p7b734ag85kop1";
        /** leanCloud的appKey */
        String APP_KEY = "835d7wncxi58z2g3csdrpwdv6cujdsrjkt5y3lgxxtzc2b2t";
        AVOSCloud.initialize(application, APP_ID, APP_KEY);

        // 设置事件响应接口
        AVIMClient.setClientEventHandler(new ChatEventHanlder.CustomNetworkHandler());
        AVIMMessageManager.setConversationEventHandler(new ChatEventHanlder.CustomConversationHandler());
        AVIMMessageManager.registerMessageHandler(AVIMTypedMessage.class, new ChatEventHanlder.MsgHandler());
        hasInit = true;
    }
}
